/**
 * input data format check
 */

var canLogin = [false, false, false, false];
var focused = [false, false, false, false];
var nickname, phoneNo, pwd, confirmPwd;

	$("#registerNickname").focusout(function(){
		focused[0]="true";
		nickname = $(this).val();
		if(nickname.length < 5 || nickname.length > 20){
			if(nickname == ""){
				$("#nameError").text("Please enter a name");
			}
			else if(nickname.length > 20 || nickname.length < 5){
				$("#nameError").text("Please enter a 5-20 character name");
			}
			$("#nameError").removeClass("hidden");
			canLogin[0] = false;
		}
		else{
			$("#nameError").addClass("hidden");
			canLogin[0] = true;
		}
	});
	$("#registerUname").focusout(function(){
		focused[1] = true;
		var acceptPhone = checkSubmitMobile();
		if(!acceptPhone){
			$("#phoneNumError").text("Please enter a valid phone number");
			$("#phoneNumError").removeClass("hidden");
			canLogin[1] = false;
		}
		else{
			$("#phoneNumError").addClass("hidden");
			canLogin[1] = true;
		}
	});
	$("#registerPsw").focusout(function(){
		focused[2]=true;
		pwd = $(this).val();
		if(pwd.length > 20 || pwd.length < 7 || pwd == ""){
			if(pwd == ""){
				$("#pswdError").text("Please enger a password");
			}
			else if(pwd.length > 20 || pwd.length < 7){
				$("#pswdError").text("Please enter a 7-20 character password");
			}
			$("#pswdError").removeClass("hidden");
			canLogin[2] = false;
		}
		else{
			$("#pswdError").addClass("hidden");
			canLogin[2] = true;
		}
	});
	$("#registerPsw2").focusout(function (){
		focused[3]=true;
		confirmPwd = $(this).val();
		if(confirmPwd != pwd || confirmPwd == ""){
			if(confirmPwd == ""){
				$("#confirmPwdError").text("Please enter a password");
				
			}
			else{
				$("#confirmPwdError").text("The two passwords do not match");
			}
			$("#confirmPwdError").removeClass("hidden");
			canLogin[3] = false;
		}
		else{
			$("#confirmPwdError").addClass("hidden");
			canLogin[3] = true;
		}
	});

/**
 * check phone number
 */

function checkSubmitMobile() {
	//if (!$("#registerUname").val().match(/^(((13[0-9]{1})|159|153)+d{8})$/)) {
	if (!$("#registerUname").val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/)) {
		return false;
	}
	return true;
}

function getLoginStatus(){
	for(var i = 0; i < canLogin.length; i ++){
		if(canLogin[i] == false){
			return false;
		}
	}
	return true;
}